package com.nd.controller.wx;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.nd.pojo.bean.Goods;
import com.nd.pojo.vo.GoodsListVo;
import com.nd.pojo.vo.wx.*;
import com.nd.service.GoodsService;
import com.nd.service.wx.SelectService;
import com.nd.service.wx.WXGoodsService;
import jdk.nashorn.internal.ir.IfNode;
import org.apache.shiro.crypto.hash.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: project2mall
 * @description: 微信商品控制类
 * @author: shit_code_builder
 * @create: 2021-06-08 11:44
 **/

@RestController
@RequestMapping("wx")
public class WXGoodController {

    @Autowired
    WXGoodsService wxGoodsService;

    @Autowired
    SelectService selectService;

    @GetMapping("/goods/category")
    public BaseRespWXVo<GoodsCategoryVO> goodsCategorySelect(Integer id){


        BaseRespWXVo<GoodsCategoryVO> baseRespWXVo = wxGoodsService.selectCategoryById(id);
        return baseRespWXVo;
    }


    @GetMapping("goods/list")
    public  BaseRespWXVo goodsListSelect(Integer categoryId, Integer page, Integer size,String keyword,String sort,String order,Boolean isHot,Boolean isNew){
        BaseRespWXVo baseRespWXVo;
        if (keyword==null&&isHot==null&&isNew==null){
            baseRespWXVo= wxGoodsService.selectGoodBycategoryId( categoryId, page, size);
        }else {
            baseRespWXVo= selectService.result(categoryId,page,size,keyword,sort,order,isHot,isNew);
        }


        return baseRespWXVo;
    }




    @GetMapping("goods/detail")
    public BaseRespWXVo<GoodDetailVO> selectGoodDetail(Integer id){

        BaseRespWXVo<GoodDetailVO> baseRespWXVo= wxGoodsService.selectGoodDetail(id);

        return baseRespWXVo;
    }

    @GetMapping("/goods/related")
    public BaseRespWXVo<Map> selectGoodRelated(Integer id){

        HashMap hashMap = new HashMap();
        ArrayList<GoodRelatedVO> goodRelatedVO=  wxGoodsService.selectGoodRelated(id);
        hashMap.put("goodsList",goodRelatedVO);

        return BaseRespWXVo.ok(hashMap);
    }




}
